package jia.ai;

import jia.core.PointXY;

import java.awt.*;
import java.awt.geom.Point2D;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import jia.game.GenericFlags;
import org.apache.log4j.Logger;

/**
 * A Point2D.Double extension implementing accessor interface PointXY.
 *
 * @version 1.0
 * @since 01/22/2006
 */
public class Point2DD extends Point2D.Double implements PointXY, Serializable{
    private static final long serialVersionUID = 0L;
    private static final Logger log = Logger.getLogger(Point2DD.class);
    
    public static void main(String[] args){
        if (GenericFlags.warningMessages) {
            log.warn(args);
        }
    }
    
    /**
     * @param x
     * @param y
     */
    public Point2DD(double x, double y){
        this.x = x;
        this.y = y;
    }
    
    /**
     * @param pointXY
     */
    public Point2DD(PointXY pointXY){
        x = pointXY.getX();
        y = pointXY.getY();
    }
    
    /**
     * @param point2D
     */
    public Point2DD(Point2D point2D){
        x = point2D.getX();
        y = point2D.getY();
    }
    
    /**
     *
     */
    public Point2DD(){
    }
    
    /**
     * @param x
     */
    public void setX(double x){
        this.x = x;
    }
    
    /**
     * @param y
     */
    public void setY(double y){
        this.y = y;
    }
    
    /**
     * @param pointXY
     */
    public void setXY(PointXY pointXY){
        x = pointXY.getX();
        y = pointXY.getY();
    }
    
    /**
     * @param x
     * @param y
     */
    public void setXY(double x, double y){
        this.x = x;
        this.y = y;
    }
    
    /**
     * @param point
     */
    public void setXY(Point point){
        x = point.x;
        y = point.y;
    }
    
    /**
     * The angle, in radians, from this point to the other point.
     * Note that the direction of 0 radians is along the
     * positive x-axis and PI/2 radians is along the positive y-axis.
     *
     * @param otherPointXY
     *
     * @return
     */
    public double angleTo(PointXY otherPointXY){
        return Math.atan2(otherPointXY.getY() - y, otherPointXY.getX() - x);
    }
    
    /**
     * @param otherPointXY
     *
     * @return
     */
    public double distanceXY(PointXY otherPointXY){
        return distance(otherPointXY.getX(), otherPointXY.getY());
    }
    
    /**
     * @return
     */
    public String toString(){
        return "(" + x + "," + y + ")";
    }
    
    /**
     * @param objectOutputStream
     *
     * @throws IOException
     */
    private void writeObject(ObjectOutputStream objectOutputStream) throws IOException{
        objectOutputStream.defaultWriteObject();
        objectOutputStream.writeDouble(x);
        objectOutputStream.writeDouble(y);
    }
    
    /**
     * @param objectInputStream
     *
     * @throws IOException
     * @throws ClassNotFoundException
     */
    private void readObject(ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException{
        objectInputStream.defaultReadObject();
        x = objectInputStream.readDouble();
        y = objectInputStream.readDouble();
    }
}
